import Vue from 'vue'
import Router from 'vue-router'
import customerService from './routers/customerService'
import assetPanorama from './routers/assetPanorama'
Vue.use(Router)
// 路由模块
const routes = [...customerService, ...assetPanorama]
// 路由滚动导航
const scrollBehavior = (to, from, savedPosition) => {
    if (savedPosition) {
        setTimeout(() => {
            window.scrollTo(savedPosition.x, savedPosition.y)
        }, 200)
    }
}
// 定义主路由
const router = new Router({
    scrollBehavior, // - only available in html5 history mode
    routes
})
// 截取url上的code，url已经encode过
// function getCodeByURL() {
//     const url = decodeURIComponent(location.href)
//     const res = url.match(/code=([^#&]+)/)
//     if (res) {
//         return res[1]
//     }
//     return ''
// }
// 按楼盘来部署公众号需要带code
// const projectCode = getCodeByURL()
// if (projectCode) {
//     localStorage.projectCode = projectCode
// }

// 相关验证拦截
router.beforeEach(function (to, from, next) {
    console.log('======to=========>', to)

    // if (to.meta && to.meta.requiresAuth) {
    //     next();
    // } else {
    next()
    // }
})
// 设置标题
router.afterEach(function (to, from) {
    if (to.meta && to.meta.title) {
        document.title = to.meta.title
    }
})
export default router
